# Maintainer: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=libsrtp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.3.0
pkgrel=1
pkgdesc="Library for SRTP (Secure Realtime Transport Protocol) (mingw-w64)"
arch=('any')
url='https://github.com/cisco/libsrtp'
license=('BSD-based')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-openssl")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/cisco/${_realname}/archive/v${pkgver}.tar.gz"
        "0002-symbolic-link-creation-removal-for-mingw-platform.patch"
        "words.txt")
sha256sums=('94093a5d04c5f4743e8d81182b76938374df6d393b45322f24960d250b0110e8'
            '596bb2fae0b2f05f7cc543e8c6f0d6432c6a243fbda97e882f5a2b22e6c6a5a8'
            '126a4ef38493313edc50b86f90dfdaf7c59ec6c948451eac228f2f3a8ab1a6ed')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p2 -i ${srcdir}/0002-symbolic-link-creation-removal-for-mingw-platform.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-openssl

  make
  make shared_library
}

check() {
  cp words.txt "${srcdir}"/build-${CARCH}/test
  cd "${srcdir}"/build-${CARCH}
  make runtest
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"
  
  for pcfile in  "${pkgdir}${MINGW_PREFIX}"/lib/pkgconfig/*.pc; do
    sed -s "s|$(cygpath -m ${MINGW_PREFIX})|${MINGW_PREFIX}|g" -i "${pcfile}"
  done
}
